import axios from 'axios';
import { Paging } from '@/types/global';
import { TreeNodeData } from '@arco-design/web-vue';

export interface FolderMessage {
  id?: string;
  name?: string;
  projectId?: string;
  teamId?: string;
  userId?: string;
  parentId?: string;
  childId?: string;
  type?: string;
  createBy?: string;
  createDate?: string;
  updateBy?: string;
  updateDate?: string;
  deleteFlag?: number;
}

export interface FileMessage {
  id?: string;
  name?: string;
  projectId?: string;
  teamId?: string;
  folderId?: string;
  fileToken?: string;
  description?: string;
  size?: string;
  type?: string;
  version?: string;
  createBy?: string;
  createDate?: string;
  updateBy?: string;
  updateDate?: string;
  deleteFlag?: number;
  isLocked?: boolean;
}

export interface FileAndFolderNodeMessage
  extends TreeNodeData,
    FileMessage,
    FolderMessage {
  /** 0:folder 1:file */
  isFileOrFolder?: number;
  children?: FileAndFolderNodeMessage[];
}

export interface FileAndFolderMessage extends FileMessage, FolderMessage {
  /** 0:folder 1:file */
  isFileOrFolder?: number;
}

export function getFolderList(id?: number) {
  return axios.get<Paging<FolderMessage>>('/cde-collaboration/folder/list', {
    params: {
      id,
    },
  });
}

export function getChildFolderList(
  projectId?: string,
  teamId?: string,
  type?: string,
  parentId = '0'
) {
  return axios.get<Paging<FolderMessage>>(
    '/cde-collaboration/folder/children',
    {
      params: {
        projectId,
        teamId,
        type,
        parentId,
        pageSize: 9999,
      },
    }
  );
}

export function getFileList(folderId?: string, fileName?: string) {
  if (folderId === undefined) return null;
  return axios.get<Paging<FileMessage>>('/cde-collaboration/file/list', {
    params: {
      folderId,
      fileName,
      pageSize: 9999,
    },
  });
}
